/** @format */

import { _decorator, Component, Node } from "cc";
import { timeStamp } from "console";
import { app } from "db://assets/FrameWork/App";
import { BaseComponent } from "db://assets/FrameWork/Module/Component/BaseComponent";
import { nsMoleEnum } from "../../../Const/MoleEunm";
import { MoleMole } from "../Mole/MoleMole";
const { ccclass, property } = _decorator;

@ccclass("MoleHole")
export class MoleHole extends BaseComponent {
    private _status: nsMoleEnum.EHoleStatus = nsMoleEnum.EHoleStatus.EMPTY;
    private _mole: MoleMole = null;

    protected init(): void {
        super.init();
        this.reset();
    }

    /**
     * 是否空置状态
     * @returns
     */
    public isEmpty(): boolean {
        return nsMoleEnum.EHoleStatus.EMPTY == this._status;
    }

    /**
     * 是否锁定状态
     * @returns
     */
    public isLock(): boolean {
        return nsMoleEnum.EHoleStatus.LOCK == this._status;
    }

    /**
     * 创建地鼠
     * @returns
     */
    public createMole(): boolean {
        if (!this.isEmpty()) return false;
        this._status = nsMoleEnum.EHoleStatus.MOLE;
        const nodeMole = app.poolMgr.getItem(nsMoleEnum.EPoolName.MOLE);
        this.setMole(nodeMole.getComponent(MoleMole));
        this._mole.setHole(this);
        this.node.addChild(nodeMole);
        return true;
    }

    /**
     * 设置当前地鼠
     * @param mole
     */
    public setMole(mole: MoleMole): void {
        this._mole = mole;
    }

    /**
     * 暂停地鼠
     */
    public pause(): void {
        if (this._mole) {
            this._mole.pause();
        }
    }

    /**
     * 继续地鼠
     */
    public resume(): void {
        if (this._mole) {
            this._mole.resume();
        }
    }

    /**
     * 重置地鼠洞
     */
    public reset(): void {
        // app.log.info("重置地洞");
        this.setMole(null);
        this._status = nsMoleEnum.EHoleStatus.EMPTY;
    }

    public release(): void {
        if (this._mole) {
            this._mole.release();
            this._mole = null;
        }
    }
}
